﻿#include "playerwgt.h"
#include <QVBoxLayout>
#include <QMouseEvent>
#include "skin/skin.h"
#include <QPainter>
PlayerWgt::PlayerWgt(QWidget *parent)
    : QWidget{parent}
{
    this->setFixedSize(1080,700);
    this->setWindowFlags(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground);

    //创建子窗口
    titleWgt_ = new titleWgt(this);
    centerWgt_ = new centerWgt(this);
    tailWgt_ = new tailWgt(this);

    //绑定信号与槽
    connect(tailWgt_,&tailWgt::sig_pause,centerWgt_,&centerWgt::Puase);
    connect(tailWgt_,&tailWgt::sig_volum,centerWgt_,&centerWgt::Volum);
    connect(centerWgt_,&centerWgt::sig_process,tailWgt_,&tailWgt::slot_process);
    //垂直布局
    QVBoxLayout* vlayout = new QVBoxLayout(this);
    vlayout->addWidget(titleWgt_);
    vlayout->setSpacing(0);
    vlayout->addWidget(centerWgt_);
    vlayout->addWidget(tailWgt_);
    vlayout->setContentsMargins(0,0,0,0);
    //设置布局
    this->setLayout(vlayout);
    //设置皮肤
    SkinMgr::inst()->setSkin(SK_PLAYER,this);
}

void PlayerWgt::mouseMoveEvent(QMouseEvent *event)
{
    if(event->buttons() & Qt::LeftButton && isPress_)
    {
        move(event->globalPos() - point_);
    }
    QWidget::mouseMoveEvent(event);
}

void PlayerWgt::mousePressEvent(QMouseEvent *event)
{
    isPress_ = true;
    point_ = event->globalPos() - this->frameGeometry().topLeft();
    QWidget::mousePressEvent(event);
}

void PlayerWgt::mouseReleaseEvent(QMouseEvent *event)
{
    isPress_ = false;
    QWidget::mouseReleaseEvent(event);
}

void PlayerWgt::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing); // 设置抗锯齿，不然边框会有明显锯齿
    QBrush brush(QColor("#1b1a20"));
    painter.setBrush(brush);
    painter.setPen(Qt::NoPen); // 不绘制边框
    painter.drawRoundedRect(this->rect(),15,15);
}

